home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / chapter11 / tryexample.java < prev    next >
Text File  |  1995-12-31  |  667b  |  34 lines

  1. /* try and catch example */
  2. class tryexample2 {
  3.  
  4.     public static void main(String args[]) {
  5.  
  6.  
  7.         try {
  8.             other();    // exception will be caught from
  9.                     // this call
  10.               System.out.println("Hey it worked!");
  11.             } 
  12.         catch(ArithmeticException e) { 
  13.               System.out.println(e.getMessage()); 
  14.             }
  15.         System.out.println("The calculations are complete!");
  16.         
  17.         other();        // exception will not be caught
  18.                     // system will issue an error and
  19.                     // terminate the run
  20.         System.out.println("I never print");
  21.  
  22.         }
  23.  
  24.         static void other() {
  25.             int a;
  26.  
  27.             a = 0;
  28. //    if (a==0) throw new NullPointerException();
  29.  
  30.             a = 10/a;
  31.             }
  32.  
  33.     }
  34.